<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <div class="nav nav-tabs">
        <h4>数据统计</h4>
    </div>
    <form class="well form-inline margin-top-20" method="post" action="">
        时间:
        <input type="text" class="form-control js-bootstrap-date" name="start_time" id="start_time"
               value="{$where_r.start_time|default=''}"
               style="width: 140px;" autocomplete="off">-
        <input type="text" class="form-control js-bootstrap-date" name="end_time" id="end_time"
               value="{$where_r.end_time|default=''}"
               style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;
        <input type="button" id="choose_time" class="btn btn-primary" value="筛选"/>
    </form>
</div>
<div>
    <div id="container" style="width:80%;height:400px; margin: 0 auto"></div>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/echarts/echarts.min.js"></script>
<script>
    $(function () {
        var chart = echarts.init(document.getElementById('container'));
        option = {
            title: {
                text: '买家分类跟进统计图',
//                subtext: '纯属虚构',
                x: 'center'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis : [
                {
                    type : 'value'
                }
            ],
            yAxis : [
                {
                    axisLabel:{
                        interval: 0
                    },
                    type : 'category',
                    data : [],
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            series: [
                {
                    itemStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(
                                0, 0, 0, 1,
                                [
                                    {offset: 0, color: '#83bff6'},
                                    {offset: 0.5, color: '#188df0'},
                                    {offset: 1, color: '#188df0'}
                                ]
                            )
                        },
                        emphasis: {
                            color: new echarts.graphic.LinearGradient(
                                0, 0, 0, 1,
                                [
                                    {offset: 0, color: '#2378f7'},
                                    {offset: 0.7, color: '#2378f7'},
                                    {offset: 1, color: '#83bff6'}
                                ]
                            )
                        }
                    },
                    name: '买家分类跟进',
                    type: 'bar',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: []
                }
            ]
        };

        function getdata(){
            var params = {
                start_time: $('#start_time').val(),
                end_time: $('#end_time').val(),
                type:'follow',
            };
            option.series[0].data = [];//清空原数据
            $.ajax({
                url: "{:url('getdata')}",
                type: 'post',
                data: params,
                dataType: "json",
                success: function (data) {
                    var sum = 0;
                    $.each(data.data.Buyer.data, function (i, e) {
                        option.yAxis[0].data.push(e.name);
                        sum += e.count;
                        option.series[0].data.push(e.count);
                    });
                    option.title.subtext = "共"+sum+"条数据";
                    $('#container').css('height',data.data.Buyer.data.length * 40 +'px');
                    chart.resize();
                    chart.setOption(option, true);
                }
            });
        }
        $('#choose_time').click(function () {
            getdata();
        });
        getdata();
        $(window).resize(function () {
            chart.resize();
        });
    });
</script>
</body>
</html>